from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-29 14:02:29.200680
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 29, Apr, 2022
Time: 14:02:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.1045
Nobs: 641.000 HQIC: -49.4879
Log likelihood: 7842.96 FPE: 2.52390e-22
AIC: -49.7311 Det(Omega_mle): 2.19566e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.325694 0.061942 5.258 0.000
L1.Burgenland 0.105094 0.039388 2.668 0.008
L1.Kärnten -0.110277 0.020648 -5.341 0.000
L1.Niederösterreich 0.196511 0.082306 2.388 0.017
L1.Oberösterreich 0.118510 0.081205 1.459 0.144
L1.Salzburg 0.258648 0.041850 6.180 0.000
L1.Steiermark 0.043878 0.055023 0.797 0.425
L1.Tirol 0.105166 0.044400 2.369 0.018
L1.Vorarlberg -0.063696 0.039239 -1.623 0.105
L1.Wien 0.026415 0.071938 0.367 0.713
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054490 0.132402 0.412 0.681
L1.Burgenland -0.033580 0.084191 -0.399 0.690
L1.Kärnten 0.040342 0.044136 0.914 0.361
L1.Niederösterreich -0.191340 0.175928 -1.088 0.277
L1.Oberösterreich 0.447921 0.173574 2.581 0.010
L1.Salzburg 0.285716 0.089454 3.194 0.001
L1.Steiermark 0.105764 0.117612 0.899 0.369
L1.Tirol 0.313687 0.094905 3.305 0.001
L1.Vorarlberg 0.022569 0.083872 0.269 0.788
L1.Wien -0.037002 0.153767 -0.241 0.810
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189293 0.031726 5.967 0.000
L1.Burgenland 0.090550 0.020174 4.489 0.000
L1.Kärnten -0.007958 0.010576 -0.752 0.452
L1.Niederösterreich 0.248702 0.042155 5.900 0.000
L1.Oberösterreich 0.157220 0.041591 3.780 0.000
L1.Salzburg 0.040519 0.021435 1.890 0.059
L1.Steiermark 0.025577 0.028182 0.908 0.364
L1.Tirol 0.086998 0.022741 3.826 0.000
L1.Vorarlberg 0.054230 0.020097 2.698 0.007
L1.Wien 0.116297 0.036845 3.156 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112006 0.031884 3.513 0.000
L1.Burgenland 0.045631 0.020275 2.251 0.024
L1.Kärnten -0.014395 0.010629 -1.354 0.176
L1.Niederösterreich 0.180323 0.042366 4.256 0.000
L1.Oberösterreich 0.327450 0.041799 7.834 0.000
L1.Salzburg 0.101621 0.021542 4.717 0.000
L1.Steiermark 0.110483 0.028323 3.901 0.000
L1.Tirol 0.098052 0.022854 4.290 0.000
L1.Vorarlberg 0.059340 0.020198 2.938 0.003
L1.Wien -0.021282 0.037030 -0.575 0.565
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114433 0.059351 1.928 0.054
L1.Burgenland -0.043170 0.037740 -1.144 0.253
L1.Kärnten -0.046238 0.019785 -2.337 0.019
L1.Niederösterreich 0.144007 0.078863 1.826 0.068
L1.Oberösterreich 0.157389 0.077808 2.023 0.043
L1.Salzburg 0.283708 0.040099 7.075 0.000
L1.Steiermark 0.056127 0.052722 1.065 0.287
L1.Tirol 0.165538 0.042543 3.891 0.000
L1.Vorarlberg 0.096778 0.037597 2.574 0.010
L1.Wien 0.073668 0.068929 1.069 0.285
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060140 0.046733 1.287 0.198
L1.Burgenland 0.030355 0.029717 1.021 0.307
L1.Kärnten 0.051449 0.015578 3.303 0.001
L1.Niederösterreich 0.205632 0.062097 3.311 0.001
L1.Oberösterreich 0.322970 0.061266 5.272 0.000
L1.Salzburg 0.038250 0.031574 1.211 0.226
L1.Steiermark 0.007117 0.041513 0.171 0.864
L1.Tirol 0.130486 0.033498 3.895 0.000
L1.Vorarlberg 0.063855 0.029604 2.157 0.031
L1.Wien 0.090623 0.054275 1.670 0.095
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173836 0.056107 3.098 0.002
L1.Burgenland 0.005719 0.035677 0.160 0.873
L1.Kärnten -0.065199 0.018703 -3.486 0.000
L1.Niederösterreich -0.097428 0.074552 -1.307 0.191
L1.Oberösterreich 0.203904 0.073555 2.772 0.006
L1.Salzburg 0.055217 0.037907 1.457 0.145
L1.Steiermark 0.239579 0.049840 4.807 0.000
L1.Tirol 0.501757 0.040217 12.476 0.000
L1.Vorarlberg 0.061183 0.035542 1.721 0.085
L1.Wien -0.076139 0.065161 -1.168 0.243
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148214 0.062217 2.382 0.017
L1.Burgenland 0.004532 0.039563 0.115 0.909
L1.Kärnten 0.060412 0.020740 2.913 0.004
L1.Niederösterreich 0.183409 0.082671 2.219 0.027
L1.Oberösterreich -0.062197 0.081565 -0.763 0.446
L1.Salzburg 0.208112 0.042036 4.951 0.000
L1.Steiermark 0.134382 0.055268 2.431 0.015
L1.Tirol 0.068602 0.044597 1.538 0.124
L1.Vorarlberg 0.145244 0.039413 3.685 0.000
L1.Wien 0.111231 0.072257 1.539 0.124
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377671 0.036629 10.311 0.000
L1.Burgenland -0.000945 0.023291 -0.041 0.968
L1.Kärnten -0.021896 0.012210 -1.793 0.073
L1.Niederösterreich 0.211688 0.048670 4.349 0.000
L1.Oberösterreich 0.226177 0.048019 4.710 0.000
L1.Salzburg 0.038807 0.024747 1.568 0.117
L1.Steiermark -0.013848 0.032537 -0.426 0.670
L1.Tirol 0.095100 0.026255 3.622 0.000
L1.Vorarlberg 0.052627 0.023203 2.268 0.023
L1.Wien 0.036780 0.042540 0.865 0.387
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036211 0.113859 0.173346 0.140895 0.102447 0.085485 0.037835 0.209782
Kärnten 0.036211 1.000000 -0.021201 0.134407 0.052494 0.090126 0.442070 -0.060849 0.092718
Niederösterreich 0.113859 -0.021201 1.000000 0.323068 0.129952 0.284157 0.075503 0.162670 0.296683
Oberösterreich 0.173346 0.134407 0.323068 1.000000 0.222067 0.310192 0.169057 0.150423 0.249584
Salzburg 0.140895 0.052494 0.129952 0.222067 1.000000 0.132133 0.097371 0.112632 0.129968
Steiermark 0.102447 0.090126 0.284157 0.310192 0.132133 1.000000 0.140048 0.121048 0.049212
Tirol 0.085485 0.442070 0.075503 0.169057 0.097371 0.140048 1.000000 0.069433 0.149955
Vorarlberg 0.037835 -0.060849 0.162670 0.150423 0.112632 0.121048 0.069433 1.000000 0.006875
Wien 0.209782 0.092718 0.296683 0.249584 0.129968 0.049212 0.149955 0.006875 1.000000